/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.wii.elpro.dao.jpa;

import com.wii.elpro.dao.JPAUtil;
import com.wii.elpro.dao.PriceListMarketingDAOInterface;
import com.wii.elpro.entity.Cabang;
import com.wii.elpro.entity.PriceListMarketing;
import com.wii.elpro.entity.Produk;
import java.util.List;
import javax.persistence.EntityManager;

/**
 *
 * @author hendro
 */
public class PriceListMarketingDAOImpl extends DAOGenericImpl implements PriceListMarketingDAOInterface {

    public PriceListMarketing getPriceList(long id) throws Exception {
        JPAUtil.beginTransaction();
        EntityManager em = JPAUtil.getEntityManager();
        try {
            return em.find(PriceListMarketing.class, id);
        } catch (Exception ex) {
            throw ex;
        }
    }

    public PriceListMarketing getPriceList(Produk produk, Cabang cabang) throws Exception {
        JPAUtil.beginTransaction();
        EntityManager em = JPAUtil.getEntityManager();
        try {
            return (PriceListMarketing) em.createQuery("SELECT plm FROM PriceListMarketing plm WHERE plm.produk=:input1 AND plm.cabang=:input2").setParameter("input1", produk).setParameter("input2", cabang).getSingleResult();
        } catch (Exception ex) {
            throw ex;
        }
    }

    public List<PriceListMarketing> getPriceLists() throws Exception {
        JPAUtil.beginTransaction();
        EntityManager em = JPAUtil.getEntityManager();
        try {
            return em.createQuery("SELECT plm FROM PriceListMarketing plm").getResultList();
        } catch (Exception ex) {
            throw ex;
        }
    }

    public List<PriceListMarketing> getPriceListsByCabang(Cabang cabang) throws Exception {
        JPAUtil.beginTransaction();
        EntityManager em = JPAUtil.getEntityManager();
        try {
            return em.createQuery("SELECT plm FROM PriceListMarketing plm WHERE plm.cabang:=input")
                    .setParameter("input", cabang)
                    .getResultList();
        } catch (Exception ex) {
            throw ex;
        }
    }
  
}
